<?php
if (!empty($question)) {
	$question_id = $question['Question']['id'];
	
	if (!empty($position)) {
		echo "No $position";
	}
	
	echo "<ul class='TabControl'>";
	echo "<li class='tab1'>";
	if ($question['Question']['question_type_id'] == QUESTION_TYPE_IMCOMPLETE_ID) {
		echo $this->Ajax->link(
									'Add question', 
		SITE_URL.'questions/DialogAddQuestion/'.$question_id,
		array('update' => 'AfterContentQuestion'.$question_id,'indicator' => 'loading', 'type' => 'GET', 'escape' => false)
		);
	}else {
		echo $this->Ajax->link(
									'Add answer', 
		SITE_URL.'answers/DialogAddAnswer/'.$question_id,
		array('update' => 'AfterContentQuestion'.$question_id,'indicator' => 'loading', 'type' => 'GET', 'escape' => false)
		);
	}
	echo "</li>";
	echo "<li  class='tab2'>";
	echo $this->Ajax->link(
									'Edit question', 
									SITE_URL.'questions/edit/'.$question['Question']['id'], 
									array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
									);
	echo "</li>";
	echo "<li  class='tab3'>";
	echo $this->Ajax->link(
									'Delete question', 
									SITE_URL.'questions/delete/'.$question['Question']['id'], 
									array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false),
									'Do you want to delete this quesion?'
									);
	echo "</li>";
	echo "</ul>";
		
	echo "<ul class='Content Question'>";
	echo "<li>".$question['Question']['content']."<li>";

	if ($question['Question']['question_type_id'] == QUESTION_TYPE_IMCOMPLETE_ID) {
		$count = 0;
		echo "<ul id='container-question-child'>";
		foreach ($question['ChildQuestion'] as $value) {
			$count ++;
			$childQuestion_id = $value['id'];
			$question_divId = "question-$question_id-child-$childQuestion_id";
			echo "<div class='clear'></div>";
			echo "<li id='$question_divId'></li>";
			
			echo $this->Javascript->codeBlock($this->Ajax->remoteFunction( 
				      array( 
				           'url' => array( 'controller' => 'Questions', 'action' => 'Show', $childQuestion_id, $count ), 
				           'update' => "$question_divId" 
				        ) 
				  )); 
		}
		echo "</ul>";
	}else{
		$div_update_answer = "update-container-answers-$question_id";
		echo "<li id='$div_update_answer'></li>";
		echo $this->Javascript->codeBlock(
			$this->Ajax->remoteFunction(
				array(
					'url' => array( 'controller' => 'answers', 'action' => 'ShowByQuestion', $question_id ), 
					'update' => "$div_update_answer" 
				 )
			));
	}
	echo "</ul>";
	echo "<div id='AfterContentQuestion$question_id'></div>";
		
} else {
	echo "Error page";
}
?>